package com.qingmi.farmer.viewmodel;

import android.databinding.ObservableField;

import com.qingmi.farmer.data.model.GoodsInfo;
import com.qingmi.farmer.data.model.Trolley;
import com.wjjun.basemvpvm.viewmodel.BaseViewModel;

/**
 * 购物车item
 * Created by 67535 on 2018/5/14.
 */
public class TrolleyItemViewModel extends BaseViewModel {

    public String id;

    public GoodsInfo goodsInfo;

    //供应商名字
    public final ObservableField<String> suppliersName = new ObservableField<>();

    //图标
    public final ObservableField<String> icon = new ObservableField<>();

    //商品名称
    public final ObservableField<String> goodsName = new ObservableField<>();

    //套餐或类型
    public final ObservableField<String> type = new ObservableField<>();

    //单价
    public final ObservableField<Double> price = new ObservableField<>(0.0);

    //总量
    public final ObservableField<Integer> count = new ObservableField<>(0);

    public final ObservableField<Boolean> check = new ObservableField<>(false);

    public final ObservableField<String> unit = new ObservableField<>();


    public TrolleyItemViewModel(Trolley trolley) {
        id = trolley.getResponseGoodId();
        goodsInfo = trolley.getGood();

        if (trolley.getGood() != null) {
            icon.set(trolley.getGood().getPic());
            goodsName.set(trolley.getGood().getName());
            type.set(trolley.getGood().getSpecificationPara());
            price.set(trolley.getGood().getPrice());
            unit.set(trolley.getGood().getUnit());

            if (trolley.getGood().getSupplier() != null) {
                suppliersName.set(trolley.getGood().getSupplier().getSupplierName());
            }
        }
        count.set(trolley.getReserveNum());
    }
}
